package com.github.zdongcoding.recyclerviewlib;

import android.os.SystemClock;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

import com.github.zdg.recyclerview.ItemOnClickListenter;
import com.github.zdg.recyclerview.RecyclerListAdapter;
import com.github.zdongcoding.recyclerviewlib.model.ItemTitle;
import com.github.zdongcoding.recyclerviewlib.viewholder.TitleViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zoudong on 2017/6/7.
 */

public class DemoActivity extends SimpleActivity {
    private List<ItemTitle> data;
    private List<ItemTitle> data1;
    private TitleViewHolder mTitleViewHolder,mFooterViewHolder;

    @Override
    void initView() {
        mRecyclerView.addItemDecoration(mLinearDividerDecoration);
        data = new ArrayList<>();
        data1 = new ArrayList<>();
        mRecyclerListAdapter = new RecyclerListAdapter<ItemTitle, TitleViewHolder>(this, data) {

        };
        mRecyclerView.setAdapter(mRecyclerListAdapter);
    }

    @Override
    void initData() {
        data.add(new ItemTitle("小狗0"));
        data.add(new ItemTitle("小狗1"));
        data.add(new ItemTitle("小狗2"));
        data.add(new ItemTitle("小狗3"));
        data.add(new ItemTitle("小狗4"));
        data.add(new ItemTitle("小狗5"));
        data.add(new ItemTitle("小狗6"));
        data.add(new ItemTitle("小狗7"));
        data.add(new ItemTitle("小狗8"));
        data.add(new ItemTitle("小狗9"));

        data1.add(new ItemTitle("add---小狗0"));
        data1.add(new ItemTitle("add---小狗1"));
        data1.add(new ItemTitle("add---小狗2"));
        data1.add(new ItemTitle("add---小狗3"));
        data1.add(new ItemTitle("add---小狗4"));
        data1.add(new ItemTitle("add---小狗5"));
        data1.add(new ItemTitle("add---小狗6"));
        data1.add(new ItemTitle("add---小狗7"));
        data1.add(new ItemTitle("add---小狗8"));
        data1.add(new ItemTitle("add---小狗9"));
        mRecyclerListAdapter.set(data);
        mTitleViewHolder = new TitleViewHolder(mRecyclerView, new ItemTitle("HEADER->时间" + SystemClock.currentThreadTimeMillis()));
        mFooterViewHolder = new TitleViewHolder(mRecyclerView, new ItemTitle("FOOTER-->时间" + SystemClock.currentThreadTimeMillis()));
        mRecyclerListAdapter.addFooter(10,mTitleViewHolder);
//        mRecyclerListAdapter.addHeader(mFooterViewHolder);
        mRecyclerListAdapter.setOnClickListenter(new ItemOnClickListenter() {
            @Override
            public void onItemClick(RecyclerView.ViewHolder vh, Object item, int pos) {
                Toast.makeText(DemoActivity.this, "pos:" + pos, Toast.LENGTH_SHORT).show();
            }
        });

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.demo, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_left:
                mRecyclerListAdapter.addAll(data1);
                break;

            case R.id.menu_top:
                mRecyclerListAdapter.addHeader(mTitleViewHolder);
                mRecyclerListAdapter.addFooter(0,mFooterViewHolder);
                mRecyclerListAdapter.remove(10);
                break;
            case R.id.menu_right:
                mRecyclerListAdapter.insert(10, new ItemTitle("insert---小狗11"));

                break;
            case R.id.menu_bottom:
                mRecyclerListAdapter.insert(10, data1);

                break;
            case R.id.menu_clear:
                mRecyclerListAdapter.removeHeader(mTitleViewHolder);
                mRecyclerListAdapter.removeFooter(mFooterViewHolder);
                break;

        }
        return true;
    }
}
